<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
</head>
<body>

This package contains the code base for the fourth design pattern lab.

<h2>Introduction</h2>
In this lab the user can add shapes by choosing in the menu. If a shape is clicked it becomes marked and by holding down the control key several shapes can be marked at once. When a square shape is marked and the user adds a shape, the new shape is added inside the square. To make some test shapes use the menu option 'Make test'.

All the names of classes and methods that you as a student create must have the prefix 'S_' followed by a describing name.<br><br>

<h2>Purpose</h2>
The purpose is to get insight into how different patterns from different categories can exist together. And to be able to recognize patterns in code and splitting them up into their base form.

<h2>Section A</h2>

<h3>Readings</h3>
Behavioral patterns chapters in GoF p. 221-344, the lectures on behavioral patterns and the lectures on roll modeling.

<h3>Instructions</h3>
Go trough the code base and recognize at least three different design patterns. Describe in a text how and why the different patterns are used. State what classes plays what roles in the patterns. One requirement is that one of the patterns is the pattern that the relationship between the shapes is based on.

<h3>Where to edit</h3>
Your own text file.

<h3>Hints</h3>
Look at the names of the different methods in the code base.

<h2>Section B</h2>

<h3>Readings</h3>
In Gof about Chain of Responsibility on p. 223-232 and the lectures.

<h3>Instructions</h3>
A shape has random position and size this results in that they overlap each other to some extent. Use the design pattern Chain of Responsibility to make all the shapes on one level cooperate to make the "bounding rectangle" (for simplicity) of the new shape not overlap any of the old ones.

<h3>Where to edit</h3>
Make changes in <em>AbstractShape</em> and in <em>ShapeFactory</em>.

<h3>Hints</h3>
Use the method <em>removeOverlap</em> to remove the overlap of the bounding rectangle.

<h2>Section C</h2>

<h3>Readings</h3>
The chapter about Visitor p. 331-344 and the chapter about Iterator p.257-271 in GoF.

<h3>Instructions</h3>
Change so that the shapes can be drawn with a Visitor or with an Iterator. There is a menu option that chooses the method used to draw the shapes. Inherit from the classes <em>AbstractVisitor</em> and <em>AbstractIterator</em>.

<h3>Where to edit</h3>
Change at the marked places in the method <em>paint</em> to make the <em>ShapePanel</em> use either the visitor or the iterator.

<h3>Hints</h3>
Use the method <em>getListOfShapes</em> on the root shape to get a list of the shapes to the iterator. There will be some cut-and-paste in this lab make sure that there are no mistakes as a result of that.

<h2>Section D</h2>

<h3>Readings</h3>
The chapter about the structural pattern Proxy on p. 207-217 in GoF.

<h3>Instructions</h3>
In the code base the class <em>SquareProxy</em> is almost empty. The assignment in this section is to make it work as a proxy for a square. The proxy should only show its content and make it available for marking when the proxy itself is open. It should also possible to add shapes to a proxy when it is open.

<h3>Where to edit</h3>
Make changes in the class <em>SquareProxy</em>.

<h3>Hints</h3>
The entire interface of the abstract classes <em>AbstractShape</em> and <em>AbstractSquare</em> must be fulfilled by the proxy.

<h2>Section E</h2>

<h3>Instructions</h3>
If it is not already done in section D change in the paint visitor and the paint iterator so that they draw the <em>SquareProxy</em> and its content when it is open as well.<br>
Create a Visitor and an Iterator that counts the total number of shapes that are added but not those in closed proxys. Write a short text of 5-10 sentences about how visitor and iterator behaved when a new class was added and when new functionality was added.

<h3>Where to edit</h3>
Where it is needed.

<h3>Hints</h3>
When the text is written, picture adding lots of classes and much functionality.

<h2>Hand in</h2>
Hand in all classes (.java-files only) that you have created.<br>
The classes <em>AbstractShape</em>, <em>AbstractVisitor</em>, <em>ShapePanel</em>, <em>SquareProxy</em> and <em>ShapeFactory</em>.<br>
The texts written about visitor and iterator and the found design patterns in the code base.

</body>
</html>
